package com.byxy.service.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.byxy.dao.AgencyDao;
import com.byxy.dao.GuideDao;
import com.byxy.entity.Agency;
import com.byxy.entity.Guide;
import com.byxy.entity.Order;
import com.byxy.service.GuideService;

@Service
@Transactional
public class GuideServiceImpl implements GuideService {
	@Resource
	private GuideDao guideDao;

	@Resource
	private AgencyDao agencyDao;

	@Override
	public List<Guide> listAll() {
		return guideDao.find();
	}

	@Override
	public void delete(int id) {
		Guide s = guideDao.get(id);
		for (Order order : s.getOrders()) {
			order.setGuide(null);
		}
		guideDao.delete(s);

	}

	@Override
	public void save(Guide guide) {
		guideDao.add(guide);
	}

	@Override
	public Guide getById(int id) {
		return guideDao.get(id);
	}

	@Override
	public void update(Guide guide) {
		guideDao.update(guide);

	}

	@Override
	public List<Guide> listPage(int page, int rows) {
		int pos = (page - 1) * rows;
		return guideDao.find(pos, rows);
	}

	@Override
	public long count() {
		return guideDao.count();
	}

	@Override
	public List<Agency> findAgency() {
		return agencyDao.find();
	}

}
